package com.xdm.ui.adapter.android;

import java.util.HashMap;

import android.app.Activity;
import android.content.Context;

import com.xdm.XManager;
import com.xdm.ui.XmDecoratedText;
import com.xdm.ui.XmImage;
import com.xdm.ui.XmItemPanel;
import com.xdm.ui.XmItemPanelView;
import com.xdm.ui.XmListAdapter;
import com.xdm.ui.XmOnItemClickListener;
import com.xdm.ui.XmUiFactory;
import com.xdm.ui.impl.XmDecoratedTextImpl;
import com.xdm.ui.impl.XmItemPanelImpl;

/**
 * The factory for XM's Android UI adapters
 * 
 * @author Alexander Lapygin
 */
public class AndroidUiFactory implements XmUiFactory {
	private Activity activity;
	static private HashMap<Context, XmUiFactory> instanceMap = new HashMap<Context, XmUiFactory>();
	private HashMap<String, XmItemPanelView> viewMap = new HashMap<String, XmItemPanelView>();
	private HashMap<String, XmImage> imageMap = new HashMap<String, XmImage>();
	
	AndroidUiFactory(Activity activity) {
		this.activity = activity;
	}

	public static XmUiFactory getInstanse(Activity activity) {
		XmUiFactory instance = (XmUiFactory) instanceMap.get(activity);
		if(instance == null) {
			instance = new AndroidUiFactory(activity);
			instanceMap.put(activity, instance);
		}
		return instance;
	}

	public XmItemPanel newPanel() {
		return new XmItemPanelImpl();
	}

	public XmListAdapter newListAdapter() {
		return new AndroidListAdapter(activity);
	}

	public XmOnItemClickListener newOnItemClickHandler(XManager xManager) {
		return new AndroidOnItemClickListener(xManager);
		
	}

	public void showAlert(String title, String message, String buttonText, boolean cancelable) {
		activity.showAlert(title, message, buttonText, cancelable);
	}

	public XmDecoratedText newDecoratedText(String name, XmImage image) {
		return new XmDecoratedTextImpl(name, image);
	}
}
